package com.sugon.controller.device;

import com.sugon.annotation.AutoLog;
import com.sugon.entity.DevRetreadRecordEntity;
import com.sugon.service.DevRetreadRecordService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 修旧利废记录/改良改善台账Controller
 *
 * @author sugon
 * @date 2019-07-19 08:33:39
 */
@Controller
@RequestMapping("devretreadrecord")
public class DevRetreadRecordController {
    @Resource
    private DevRetreadRecordService devRetreadRecordService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("devretreadrecord:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<DevRetreadRecordEntity> devRetreadRecordList = devRetreadRecordService.queryList(query);
        int total = devRetreadRecordService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(devRetreadRecordList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("devretreadrecord:info")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        DevRetreadRecordEntity devRetreadRecord = devRetreadRecordService.queryObject(id);

        return R.ok().put("devRetreadRecord", devRetreadRecord);
    }

    /**
     * 保存
     */
    @AutoLog("保存-修旧利废记录/改良改善台账")
    @RequestMapping("/save")
    @RequiresPermissions("devretreadrecord:save")
    @ResponseBody
    public R save(@RequestBody DevRetreadRecordEntity devRetreadRecord) {
        devRetreadRecordService.save(devRetreadRecord);

        return R.ok();
    }

    /**
     * 完善维修记录
     */
    @RequestMapping("/update")
    @RequiresPermissions("devretreadrecord:update")
    @ResponseBody
    public R update(@RequestBody DevRetreadRecordEntity devRetreadRecord) {
        devRetreadRecordService.perfect(devRetreadRecord);
        return R.ok();
    }

    /**
     * 审核
     */
    @AutoLog("审核-修旧利废记录/改良改善台账")
    @RequestMapping("/check")
    @RequiresPermissions("devretreadrecord:check")
    @ResponseBody
    public R check(@RequestBody String[] ids) {
        devRetreadRecordService.check(ids);
        return R.ok();
    }

    /**
     * 逻辑删除
     */
    @AutoLog("逻辑删除-修旧利废记录/改良改善台账")
    @RequestMapping("/updateDel")
    @RequiresPermissions("devretreadrecord:delete")
    @ResponseBody
    public R updatedel(@RequestBody DevRetreadRecordEntity devRetreadRecord) {
        DevRetreadRecordEntity retreadRecord = devRetreadRecordService.queryObject(devRetreadRecord.getId());
        if (retreadRecord == null) {
            return R.error("记录不存在，请确认！");
        }
        retreadRecord.setDelFlag(devRetreadRecord.getDelFlag());
        devRetreadRecordService.update(retreadRecord);
        return R.ok();
    }

    /**
     * 删除
     */
    @AutoLog("删除-修旧利废记录/改良改善台账")
    @RequestMapping("/delete")
    @RequiresPermissions("devretreadrecord:delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        devRetreadRecordService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<DevRetreadRecordEntity> list = devRetreadRecordService.queryList(params);

        return R.ok().put("list", list);
    }
}
